var obj = [1,2,3,[4]]
function deepCopy(obj)
{
    let temp = Array.isArray(obj) ? [] : {};
    for(const i in obj)
    {
        // console.log(obj[i]);
        if(typeof obj[i] === 'object')
        {
            deepCopy(obj[i]);
        }
        else
        {
            temp[i] = obj[i];
        }
    }
    return temp;
}
var fn = new deepCopy(obj);
fn[2] = 8;
console.log(obj);
console.log(fn);